//
//  Constant+Height.swift
//  BasicTools
//
//  Created by Ting Han on 2022/3/12.
//

import Foundation
import UIKit

let damping: Double = 0.78

var keyWindow: UIWindow {
    if #available(iOS 15, *) {
        if let key = (UIApplication.shared.connectedScenes.first(where: { $0 is UIWindowScene }) as? UIWindowScene)?.keyWindow {
            return key
        }
    }
    
    if #available(iOS 13, *) {
        return UIApplication.shared.windows.first!
    } else {
        return UIApplication.shared.keyWindow!
    }
}

var topEdageHeight: CGFloat {
    let height: CGFloat = 64
    if #available(iOS 15.0, *) {
        if let topPadding =  (UIApplication.shared.connectedScenes.first(where: { $0 is UIWindowScene }) as? UIWindowScene)?.keyWindow?.safeAreaInsets.top {
            return height + topPadding
        }
    }
    
    if #available(iOS 13.0, *) {
        if let topPadding = UIApplication.shared.windows.first?.safeAreaInsets.top {
            return height + topPadding
        }
    }
    
    if #available(iOS 11.0, *) {
        if let topPadding = UIApplication.shared.keyWindow?.safeAreaInsets.top {
            return height + topPadding
        }
    }
    
    return height
}

var bottomSafeArea: CGFloat {
    if #available(iOS 15.0, *) {
        if let bottom =  (UIApplication.shared.connectedScenes.first(where: { $0 is UIWindowScene }) as? UIWindowScene)?.keyWindow?.safeAreaInsets.bottom {
            return bottom
        }
    }
    var result: CGFloat = 0
    if #available(iOS 11.0, *) {
        result = UIApplication.shared.keyWindow?.safeAreaInsets.bottom ?? 0
    }
    return result
}

